<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .errorInfo{
            color: red;
            font-size: 12px;
        }
    </style>

    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        var totalPrice;
        window.onload = function (){
            totalPrice = getQuery("totalPrice");
        }

        async function addOrder(){
            var info = await ajaxGet("/order/add",{
                name:$("name").value,
                address:$("address").value,
                phone:$("phone").value,
                money:totalPrice
            });
            if(info == "ok"){
                location.href = "/html/custom/success.html";
            }
            else{
                var divArray = document.getElementsByClassName("errorInfo");
                for(var i=0;i<divArray.length;i++){
                    divArray[i].innerHTML = "";
                }

                for(var i=0;i<info.length;i++){
                    var errorObj = info[i];
                    $(errorObj.field + "Div").innerHTML = errorObj.defaultMessage;
                }
            }
        }
    </script>
</head>
<body>
    <h2>请完善订单信息</h2>
    收货人：<input type="text" id="name"><br>
    <div id="nameDiv" class="errorInfo"></div>
    送货地址：<input type="text" id="address"><br>
    <div id="addressDiv" class="errorInfo"></div>
    收货人电话：<input type="text" id="phone"><br>
    <div id="phoneDiv" class="errorInfo"></div>
    <input type="button" value="提交订单" onclick="addOrder()">
</body>
</html>